package main;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.jdo.PersistenceManager;
import javax.mail.Multipart;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.PageContext;
import com.sun.xml.internal.stream.Entity.ExternalEntity;
import com.oreilly.servlet.MultipartRequest;

import DBClasses.Game;
import DBClasses.GameType;
import DBClasses.NewsLetter;
import DBClasses.User;

@SuppressWarnings("serial")
public class AddCategory extends BaseServlet
{
	@SuppressWarnings({ "unused", "rawtypes", "unchecked" })
	@Override
	protected void action(HttpServletRequest req, HttpServletResponse resp)
			throws IOException, ServletException
	{
		PersistenceManager manager = PMF.get().getPersistenceManager();		
		List<GameType> gts = (List<GameType>) manager.newQuery(
				"select from " + GameType.class.getName() + " where name == '"
						+ req.getParameter("name").toString() + "'")
				.execute();
		String result="fail";
		if(gts==null || gts.size()<=0)
		{
			GameType new_gt=new GameType(req.getParameter("name").toString());
			manager.makePersistent(new_gt);
			result="success";
		}
		manager.close();
		resp.getWriter().write(result);
	}
}
